package pro.shuangxi.file;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author ：mengshx
 * @date ：Created in 2022/4/5 12:45
 * @description：文件操作相关
 */
public class FileUtils {
    public static String readStringFromClassPath(String path) throws IOException {
        Resource resource = new ClassPathResource(path);
        InputStream is = resource.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String data = null;
        StringBuilder stringBuilder = new StringBuilder();
        while((data = br.readLine()) != null) {
            stringBuilder.append(data);
        }
        br.close();
        isr.close();
        is.close();
        return stringBuilder.toString();
    }
}
